package dq.study.designmodel.principle.开闭原则;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dongqun
 * @date 2020/9/16 11:09
 */
public class Button {
    private List<ButtonListener> listeners = new ArrayList<ButtonListener>();

    public Button() {
    }

    public void addListener(ButtonListener listener){
        listeners.add(listener);
    }


    public void press(){
        // 观察者模式
        for (ButtonListener listener : listeners) {
            listener.pressButton();
        }
    }
}
